<?php

require_once("Dao.php");

/**
 * DAO de l'objet CDR.
 * 
 * @author Arthur
 */
class CdrStatsDao extends Dao {

    protected static $tableName = "cdr_stats";

    /**
     * Liste complète
     */
    public static function getAll() {
        return parent::find(self::$tableName);
    }

    /**
     * Liste complète des noms de fichiers
     */
    public static function getAllFilenames() {
        $results = parent::query('SELECT FileName FROM ' . self::$tableName . ' GROUP BY FileName ORDER BY id DESC;');
        $ret = array();
        foreach ($results as $result) {
            $ret[] = $result['FileName'];
        }
        return $ret;
    }

    /**
     * Insert un bunch de données dans la table
     * @param string $valuesString
     */
    public static function insertBunch($valuesString) {
        $q = 'INSERT INTO ' . self::$tableName
        . '( Filename,'
        . ' SubscriberNumber,'
        . ' LastName,'
        . ' FirstName,'
        . ' RatePlan,'
        . ' Msisdn,'
        . ' RecordDate,'
        . ' SourceId,'
        . ' CallType,'
        . ' StartDate,'
        . ' StartTime,'
        . ' Duration,'
        . ' ChargeBand,'
        . ' Charge,'
        . ' CallingNumber,'
        . ' DialedNumber,'
        . ' CountryCode,'
        . ' NumberType,'
        . ' Location,'
        . ' DestinationOrigin,'
        . ' TalkPlanInclusion,'
        . ' ChargeBeforeTalkPLan,'
        . ' TalkplanName) VALUES ' . $valuesString;
        
        return parent::query($q);
    }

}
